package cn.edu.scau.cmi.heyaqing.client;

import cn.edu.scau.cmi.heyaqing.abstractFactory.AutoInsurance;
import cn.edu.scau.cmi.heyaqing.abstractFactory.InsuranceAbstractFactory;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;

public class AbstractFactoryClient extends Application{

	protected VBox getPane(){
		HBox hboxTop = new HBox(10);
		hboxTop.setPadding(new Insets(10,10,10,10)); 
		
		ImageView pic = new ImageView(new Image("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&se"
				+ "c=1554903145048&di=316caee9b5c3bdc32d13a7f351c64211&imgtype=0&src=http%3A%2F%2Fimg.mp.itc.cn%2Fu"
				+ "pload%2F20161115%2F9b8c8b2a575d4289b7d44d2aa82e5b7b_th"
				+ ".jpg"));
		pic.setFitHeight(280);
		pic.setFitWidth(250);
		hboxTop.getChildren().add(pic);
		
		GridPane info = new GridPane();
		info.setHgap(20);
		info.setVgap(80);

		info.add(new Label("������"), 0, 0);
		info.add(new Label("������"), 1, 0);
		info.add(new Label("ѧ�ţ�"), 2, 0); 
		info.add(new Label("201627010303"), 3, 0);
		info.add(new Label("��ѡ����"), 0, 1);
		
		ComboBox<String> cbo1 = new ComboBox<>();
		cbo1.setValue("�й����ٱ���");
		String[] kind1 = {"�й����ٱ���","ƽ������"};
		ObservableList<String> items1 = FXCollections.observableArrayList(kind1);
		cbo1.getItems().addAll(items1);
		info.add(cbo1, 1, 1);
		
		ComboBox<String> cbo2 = new ComboBox<>();
		cbo2.setValue("��ʻԱ��������");
		String[] kind2 = {"��ʻԱ��������","������","��Ա����","�����¹�"};
		ObservableList<String> items2 = FXCollections.observableArrayList(kind2);
		cbo2.getItems().addAll(items2);
		info.add(cbo2, 3, 1);
		
		Button btnShow = new Button("��ʾ������Ϣ");
		info.add(btnShow,1, 2);
		
		hboxTop.getChildren().add(info); 
 		
		HBox hboxBottom = new HBox();
		hboxBottom.setPadding(new Insets(10,10,10,10));
		
		TextArea descr = new TextArea();
		descr.setFont(new Font("Serif",20));
		descr.setWrapText(true);
		descr.setEditable(false);
		hboxBottom.getChildren().add(descr);
		
		
		VBox vbox = new VBox();
		vbox.getChildren().addAll(hboxTop,hboxBottom);
		
		btnShow.setOnAction(e->{

			String classes = cbo1.getValue();
			String type = cbo2.getValue();
			String str = null;
			InsuranceAbstractFactory bf = InsuranceAbstractFactory.getBuildingFactory(classes);
			
			if(type.equals("��ʻԱ��������")) {
				AutoInsurance ins = bf.getBodyInjur();
				str = ins.getInfo();
			}
			else if(type.equals("������")) {
				AutoInsurance ins = bf.getCarDamage();
				str = ins.getInfo();
			}	
			else if(type.equals("��Ա����")) {
				AutoInsurance ins = bf.getPersonInjur();
				str = ins.getInfo();
			}
			else if(type.equals("�����¹�")) {
				AutoInsurance ins = bf.getCom();
				str = ins.getInfo();
			}
			
			descr.setText(str);
		});
		
		return vbox;
	}
	
	public void start(Stage primaryStage) {
		
		Scene scene = new Scene(getPane());
		primaryStage.setScene(scene);
		primaryStage.setTitle("ʵ���������󹤳�ģʽ");
		primaryStage.show();
	}
	public static void main(String[] args) {
		// TODO �Զ����ɵķ������

		Application.launch(args);
	}

}
